package com.wwwarehouse.taskcenter.fragment.inventory_query;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.common.activity.CaptureActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.X5WebView;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.custom_view.ColumnChartView;

import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;

/**
 * @创建者 chenchao.
 * @创建时间 2017/8/30 16:47
 * @描述 ${TODO}
 */
public class QueryInventoryFragment extends BaseFragment implements TextView.OnEditorActionListener {

    private View      mView;
    private EditText  mEtGoodSku;
    private ImageView mIvQuery;
    private TextView  mTvNoGood;
    private ImageView mIvGoodPng;
    private TextView  mTvGoodName;
    private X5WebView mWebGoodQuery;
    private ColumnChartView mCcvUse;
    private ColumnChartView mCcvIn;
    private RelativeLayout mRlCcv;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_query_inventory, container, false);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    private void initView() {
        //输入SKU的edittext
        mEtGoodSku = (EditText) mView.findViewById(R.id.et_good_sku);
        mEtGoodSku.setOnEditorActionListener(this);
        //查询刚进来的图片 以及查询没商品时显示的图片
        mIvQuery = (ImageView) mView.findViewById(R.id.iv_query_inventory);
        //没有商品显示的文字
        mTvNoGood = (TextView) mView.findViewById(R.id.tv_no_good);
        //带有柱形图的整个布局
        mRlCcv = (RelativeLayout) mView.findViewById(R.id.rl_ccv);
        //商品的图片
        mIvGoodPng = (ImageView) mView.findViewById(R.id.iv_good_png);
        //商品的名字
        mTvGoodName = (TextView) mView.findViewById(R.id.tv_good_name);
        //可用库存的柱形图
        mCcvUse = (ColumnChartView) mView.findViewById(R.id.ccv_use);
        mCcvUse.setData(50,100,50,mActivity.getResources().getColor(R.color.common_color_p50c2_f7a82f));
        //在库库存的柱形图
        mCcvIn = (ColumnChartView) mView.findViewById(R.id.ccv_in);
        mCcvIn.setData(80,100,50,mActivity.getResources().getColor(R.color.common_color_p50c1_337cff));
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof QueryInventoryFragment) {
            mActivity.setTitle(getString(R.string.query_inventory));
        }
    }

    @Override
    public void requestDatas() {
        //扫一扫
        Intent it = new Intent(mActivity, CaptureActivity.class);
        startActivityForResult(it, 11);
    }

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        switch (actionId) {
            case IME_ACTION_DONE:

                break;
        }
        return true;
    }
}
